/**
 * Created by Administrator on 2016/11/29.
 */


//必须在服务器上才能看到效果！
window.onload = function () {
    loadingAllVideos();
}

function loadingAllVideos() {
    debugger;
    $.ajax({
        url: rootUrl() + '/admin/video/srvideopoint/loadall',
        type: 'post',
        cache: false,
        data: "{}",
        contentType: "application/json",
        datatype: "json",
        success: function (d) {
            debugger;
            if (d.errorCode == 0) {
                $.each(d.obj, function (index, element) {
                    appendHtml(element);
                });
            } else {
                var msg = d.msg;
                alert("获取视频点失败");
            }
        }
    })
}

//全景图参数配置函数
function appendHtml(element) {

    debugger;
    var url = "rtsp://" + element.account + ":" + element.password + "@" + element.url + ":554/Streaming/Channels/101?transportmode=unicast";

    // var url = "rtsp://admin:admin123@192.168.201.112:554/Streaming/Channels/101?transportmode=unicast";//rtsp��Ƶ
    if (url) {
        theHtml = "<div class='col-md-4 style='margin:10px'>"
        theHtml += '<object type="application/x-vlc-plugin" pluginspage="http://www.videolan.org/"  events="false" width="400" height="340">' +
            '<param name="mrl" value="' + url + '" />' +
            '<param name="volume" value="50" />' +
            '<param name="autoplay" value="true" />' +
            '<param name="loop" value="false" />' +
            '<param name="play" id="isPlay" value="true" />' +
            '<param name="fullscreen" value="false" />' +
            '<param name="controls" value="false" />' +
            '</object>';
        theHtml += "</div>";
    } else {
        theHtml = "暂无视频连接";
    }
    $("#player").append(theHtml);
}

function urlPara(key) {
    var name, value;
    var str = location.href; //取得整个地址栏
    str = decodeURI(str);
    var num = str.indexOf("?")
    str = str.substr(num + 1); //取得所有参数   stringvar.substr(start [, length ]

    var arr = str.split("&"); //各个参数放到数组里
    var paras = [];
    for (var i = 0; i < arr.length; i++) {
        num = arr[i].indexOf("=");
        if (num > 0) {
            name = arr[i].substring(0, num);
            value = arr[i].substr(num + 1);
            paras[name] = value;
        }
    }
    if (null != key) {
        return paras[key]
    }
    return paras;
};

function rootUrl() {
    var curWwwPath = window.document.location.href;

    //获取主机地址之后的目录如：/Tmall/index.jsp
    var pathName = window.document.location.pathname;
    var pos = curWwwPath.indexOf(pathName);

    //获取主机地址，如： http://localhost:8080
    var localhostPath = curWwwPath.substring(0, pos);
    var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
    if (projectName == '/admin' || projectName == 'static') {
        projectName = '';
    }
    //获取带"/"的项目名，如：/Tmall

    return localhostPath + projectName;
}